package com.ruifu.proj.controller;

import com.fhzncloud.cloud.common.core.util.R;
import com.ruifu.common.vo.ResultVO;
import com.ruifu.proj.dto.ptmain.PmPlanVerDTO;
import com.ruifu.proj.service.PmPlanVerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author nyr
 * @create 2019/8/7
 */
@RestController
@CrossOrigin
@RequestMapping("/pmPlanVer")
public class PmPlanVerController {

    @Autowired
    private PmPlanVerService pmPlanVerService;



    /**
     * 批准项目版本计划
     *
     * @param pmPlanVerDTOList
     * @return
     */
    @PostMapping(value = "/updatePvStatus")
    public ResultVO updatePvStatus(@RequestBody List<PmPlanVerDTO> pmPlanVerDTOList) {
        try {
            pmPlanVerService.updatePvStatus(pmPlanVerDTOList);
            return new ResultVO(true, "批准成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultVO(false, e.getMessage());
        }
    }

    /**
     * 升版
     *
     * @param pmPlanVerDTOList
     * @return
     */
    @PostMapping(value = "/newVersion")
    public ResultVO newVersion(@RequestBody List<PmPlanVerDTO> pmPlanVerDTOList) {
        try {
            pmPlanVerService.newVersion(pmPlanVerDTOList);
            return new ResultVO(true, "升版成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultVO(false, e.getMessage());
        }
    }

    /**
     * 撤销申请
     * @param pvId
     * @return
     */
    @GetMapping(value = "/revoke/{pvId}")
    public R revoke(@PathVariable(value = "pvId") Long pvId) {
        try {
            pmPlanVerService.revoke(pvId);
            return R.ok(true, "撤销成功");
        } catch (Exception e) {
            e.printStackTrace();
            return R.failed(true, "撤销失败");
        }
    }

}
